<template>
  <avue-crud v-on="tableEvent"
             :option="candidateUserOption"
             :loading="loading"
             :permission="getBtnPermission"
             :data="candidateUserList"
  ></avue-crud>
</template>

<script>
import actTaskApi from "@/api/start/activiti/actTaskApi";
import taskCandidateOption from "./taskCandidateUserOption";
import useUserStore from "@/stores/useUserStore";

export default {
  name: "taskCandidateUser",
  computed: {
    dialogTitle() {
      return ""
    },
    candidateUserOption() {
      return taskCandidateOption
    },
    permissionBtn() {
      return taskCandidateOption.permissionBtn
    },
    tableEvent() {
      return {
        'row-save': this.rowSave,
        'row-del': this.rowDel,
        'refresh-change': this.loadTaskCandidateUser,
      }
    },
  },
  data() {
    return {
      loading: false,
      taskModel: {},
      candidateUserList: [],

    }
  },
  created() {

  },
  methods: {
    init(row) {
      this.taskModel = row;
      this.loading = true;
      this.candidateUserList = []
      this.loadTaskCandidateUser()
    },
    getBtnPermission(btnKey, row, index, defaultValue = true) {
      if (!this.permissionBtn) {
        return defaultValue
      }
      if (!this.permissionBtn[btnKey]) {
        return defaultValue;
      }
      return useUserStore().hasPermission(this.permissionBtn[btnKey], false);
    },
    loadTaskCandidateUser() {
      actTaskApi.listTaskCandidateUser(this.taskModel.taskInstId).then(res => {
        this.candidateUserList = res.data.data;
      }).finally(() => {
        this.loading = false;
      })
    },
    rowSave(row, done, loading) {
      let item = {};
      item.userId = row.userId
      item.startUserType = "admin_user"
      console.log("item", item)
      actTaskApi.addTaskCandidateUser(this.taskModel.taskInstId, item).then(res => {
        this.$message.success("操作成功");
        done()
        this.loadTaskCandidateUser()
      }).finally(() => {
        loading()
      })
    },
    rowDel(row, index) {
      this.$confirm(`此操作将删除【${row.userFinalName}】审核人！ 是否继续?`, '系统提示', {
        confirmButtonText: '是',
        cancelButtonText: '否',
        type: 'warning'
      }).then(() => {
        let item = {};
        item.userId = row.id
        item.startUserType = "admin_user"
        return actTaskApi.delTaskCandidateUser(this.taskModel.taskInstId, [item])
      }).then(res => {
        this.$message.success("操作成功");
        this.loadTaskCandidateUser()
      })
    },
    handleClose() {
      this.candidateUserList = []
      this.loading = false
      this.taskModel = {};
    },

  }
}
</script>

<style scoped>

</style>
